<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
	<canvas id="canvas" width="500" height="500" style="border: 1px solid #ccc"></canvas>

</body>
</html>

<script type="text/javascript">
	var canvas = document.getElementById('canvas');
	var context = canvas.getContext('2d');
	var g = context.createLinearGradient(0,0,300,100);
	g.addColorStop(0,'red');
	g.addColorStop(0.15,'orange');
	g.addColorStop(0.3,'yellow');
	g.addColorStop(0.45,'green');
	g.addColorStop(0.6,'cyan');
	g.addColorStop(0.75,'blue');
	g.addColorStop(1,'purple');
	context.fillStyle = g;
	context.fillRect(0,0,300,100)
</script>